<template>
	<div class="constant-checkbox" >
		<a-radio-group  v-model="val">
			<a-radio  :value="key" :key="key" v-for="(value, key) in data">{{value}}</a-radio>
		</a-radio-group>
	</div>
</template>

<script>
  import {prefix} from '../config';
  import {constantNameMap} from '../../../constants';
  export default {
    name: prefix + 'ConstantRadio',
    props: {
      value: {
        type: String,
        default: ''
      },
      type: {
        type: String,
        require: true
      },
      invalidKeys: {
        type: String,
        default: ''
      }
    },
    watch: {
      value (val) {
        this.val = val;
      },
      val () {
        this.updateValue();
      }
    },
    data () {
      return {
        val: this.value
      };
    },
    computed: {
      data () {
        let constant = constantNameMap[this.type];
        let retObj = {};
        if (constant) {
          let invalidKeys = ',' + this.invalidKeys + ',';
          for (let key in constant) {
            if (invalidKeys.indexOf(',' + key + ',') !== -1) {
              continue;
            }
            retObj[key] = constant[key];
          }
        }
        return retObj;
      }
    },
    methods: {
      updateValue () {
        this.$emit('input', this.val);
        this.$emit('change', this.val);
      }
    }
  };
</script>
